home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000086_icon-group-sender _Tue Apr 19 14:32:34 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 19 Apr 1994 15:53:29 MST
  2. Date: Tue, 19 Apr 1994 14:32:34 -0500
  3. From: John David Stone <stone@math.grin.edu>
  4. Message-Id: <199404191932.OAA00763@russell.math.grin.edu>
  5. To: rjhare@festival.ed.ac.uk
  6. Cc: icon-group@cs.arizona.edu
  7. In-Reply-To: R J Hare's message of 19 Apr 94 14:03:10 BST <9404191403.aa04644@uk.ac.ed.festival>
  8. Subject: random numbers
  9. Status: R
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12.         R. J. Hare writes:
  13.  
  14. >           I have a program in which I have an integer which marks the
  15. >  upper end of a range from which I wish to randomly select a value. I am
  16. >  using: 
  17. >
  18. >  i:=?range
  19. >
  20. >  so, if I have previously set range to (say) 13, I should get i in the
  21. >  range 1..13. In fact, I am getting i equals 1 or 3, ie: ? is apparently
  22. >  treating range as a 2 character string and returning randomly the value
  23. >  of the 1st or 2nd character in the string. Is this behaviour correct?
  24.  
  25.         It is if the value of `range' is really a string.  How did this
  26. variable acquire its value in the first place?  If it was typed in from
  27. the keyboard in response to a prompt, e.g.,
  28.  
  29.                 writes("Number, please: ")
  30.                 range := read()
  31.  
  32. then the value that is assigned to `range' really is a string, and if you
  33. want to deal with an integer you should change the second statement to
  34. something like
  35.  
  36.                 (range := integer(read())) | stop("non-integer input")
  37.  
  38. ------  John David Stone - Lecturer in Computer Science and Philosophy  -----
  39. --------------  Manager of the Mathematics Local-Area Network  --------------
  40. --------------  Grinnell College - Grinnell, Iowa 50112 - USA  --------------
  41. --------  stone@math.grin.edu - (515) 269-3181 - stone@grin1.bitnet  --------
  42.